/*
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#ifndef HI183X_PORT_H
#define HI183X_PORT_H

#include <imu/imu.h>
#include <mc/engine.h>
#include <ncsi_over_mctp/ncsi_over_mctp_mellanox.h>

#include "cx4_om.h"
#include "interface/network_port.h"
#include "interface/network_port/link_info.h"
#include "interface/network_port/lldp_receive.h"
#include "interface/network_port/metrics.h"

namespace dev {
using ncsi_over_mctp_mellanox_ptr = std::shared_ptr<ncsi_over_mctp_mellanox>;

class cx4_port : public mc::engine::object<cx4_port> {
public:
    MC_OBJECT(
        cx4_port, "NetworkPort", "NicPort/${PortId}",
        (NetworkPort)(NetworkPort_LinkInfo)(NetworkPort_LLDPReceive)(NetworkPort_Metrics))
    cx4_port()  = default;
    ~cx4_port() = default;
    bool start();
    bool stop();
    bool init(mc::mutable_dict& csr_object, const mc::dict& connector);

    bool start_ncsi_protocol(ncsi_over_mctp_mellanox_ptr ncsi_over_mctp, mc::milliseconds interval,  
                             uint8_t package_id);
    void stop_ncsi_protocol();
    bool update_port_bdf(imu_pcie_device_req_t& pcie_device_info);
    bool verify_did_vid_svid_sdid(imu_pcie_device_req_t& pcie_device_info);
    NetworkPort                    m_network_port;
    NetworkPort_LinkInfo           m_network_port_link_info;
    NetworkPort_LLDPReceive        m_network_port_lldp_receive;
    NetworkPort_Metrics            m_network_port_metrics;

    cx4_optical_module* m_optical_module = nullptr;
    
    // IMU对象，用于PCI信息验证
    std::unique_ptr<imu> m_imu = nullptr;
};

} // namespace dev

#endif // HI183X_PORT_H
